package com.zx.sdk.listener;

import android.app.Activity;
import android.app.AlertDialog;

import com.zx.sdk.ZxSDK;
import com.zx.sdk.league.member.BaseLeagueMember;
import com.zx.sdk.model.AdInfo;
import com.zx.sdk.model.ZxError;
import com.zx.sdk.util.ConfigHelper;
import com.zx.sdk.util.LogHelper;
import com.zx.sdk.util.ToastHelper;
import com.zx.sdk.util.ZxEventHelper;

public abstract class BaseZxSplashListener implements ZxSplashListener {
    private OnADExposeListener onADExposeListener;
    private OnPreloadErrorListener mOnPreloadErrorListener;
    private OnShowErrorListener mOnShowErrorListener;

    @Override
    public void onADClicked(BaseLeagueMember<?, ?, ?, ?,?> member, AdInfo adInfo) {
        LogHelper.d("联盟=" + member.getName(), "Splash广告onADClicked", "appId=" + adInfo.getMapAppid(), "pid=" + adInfo.getMapPid());
        ZxEventHelper.record(ZxSDK.SPLASH, ZxEventHelper.CLICK, adInfo, member);
        Activity topActivity = ZxSDK.topActivityRef.get();
        if (topActivity != null && !topActivity.isDestroyed() && ConfigHelper.needWarningTips(member)) {
            new AlertDialog.Builder(topActivity)
                .setTitle("温馨提示")
                .setMessage(WARNING_TIP)
                .setPositiveButton("确定", null)
                .show();
        } else {
            ToastHelper.showToast(WARNING_TIP);
        }
        onADClicked();
    }

    @Override
    public void onADDismissed(BaseLeagueMember<?, ?, ?, ?,?> member, AdInfo adInfo) {
        LogHelper.d("联盟=" + member.getName(), "Splash广告onADDismissed", "appId=" + adInfo.getMapAppid(), "pid=" + adInfo.getMapPid());
        onADDismissed();
    }

    @Override
    public void onADExposure(BaseLeagueMember<?, ?, ?, ?,?> member, AdInfo adInfo) {
        LogHelper.d("联盟=" + member.getName(), "Splash广告曝光", "appId=" + adInfo.getMapAppid(), "pid=" + adInfo.getMapPid());
        ZxEventHelper.record(ZxSDK.SPLASH, ZxEventHelper.EXPOSE, adInfo, member);
        ZxSDK.notifyClearBidding(ZxSDK.SPLASH, adInfo.getMapPid());
        onADExposure();
        if (this.onADExposeListener != null) {
            this.onADExposeListener.onADExpose();
        }
    }

    @Override
    public void onADLoaded(BaseLeagueMember<?, ?, ?, ?,?> member, long l, AdInfo adInfo) {
        LogHelper.d("联盟=" + member.getName(), "Splash广告onADLoaded", "appId=" + adInfo.getMapAppid(), "pid=" + adInfo.getMapPid());
        ZxEventHelper.record(ZxSDK.SPLASH, ZxEventHelper.LOADED, adInfo, member);
        onADLoaded(l);
    }

    @Override
    public void onADPresent(BaseLeagueMember<?, ?, ?, ?,?> member, AdInfo adInfo) {
        LogHelper.d("联盟=" + member.getName(), "Splash广告onADPresent", "appId=" + adInfo.getMapAppid(), "pid=" + adInfo.getMapPid());
        onADPresent();
    }

    @Override
    public void onADTick(BaseLeagueMember<?, ?, ?, ?,?> member, long l, AdInfo adInfo) {
        LogHelper.d("联盟=" + member.getName(), "Splash广告onADTick", "appId=" + adInfo.getMapAppid(), "pid=" + adInfo.getMapPid());
        onADTick(l);
    }

    @Override
    public void onNoAD(BaseLeagueMember<?, ?, ?, ?,?> member, ZxError error, AdInfo adInfo) {
        LogHelper.e("联盟=" + member.getName(), "Splash广告onNoAD error = " + error + "", "appId=" + adInfo.getMapAppid(), "pid=" + adInfo.getMapPid());
        onNoAD(error);
        if (mOnShowErrorListener != null) {
            mOnShowErrorListener.onError(error, adInfo);
        }
    }

    @Override
    public void onPreLoadNoAD(BaseLeagueMember<?, ?, ?, ?,?> member, ZxError error, AdInfo adInfo) {
        LogHelper.e("联盟=" + member.getName(), "Splash广告onPreLoadNoAD error = " + error + "", "appId=" + adInfo.getMapAppid(), "pid=" + adInfo.getMapPid());
        onPreLoadNoAD(error);
        if (mOnPreloadErrorListener != null) {
            mOnPreloadErrorListener.onError(error, adInfo);
        }
    }

    @Override
    public void onDownloadTipsDialogShow(BaseLeagueMember<?, ?, ?, ?,?> member, AdInfo adInfo) {
        LogHelper.d("联盟=" + member.getName(), "Splash广告onDownloadTipsDialogShow", "appId=" + adInfo.getMapAppid(), "pid=" + adInfo.getMapPid());
        onDownloadTipsDialogShow();
    }

    @Override
    public void onDownloadTipsDialogDismiss(BaseLeagueMember<?, ?, ?, ?,?> member, AdInfo adInfo) {
        LogHelper.d("联盟=" + member.getName(), "Splash广告onDownloadTipsDialogDismiss", "appId=" + adInfo.getMapAppid(), "pid=" + adInfo.getMapPid());
        onDownloadTipsDialogDismiss();
    }

    @Override
    public void onDownloadTipsDialogCancel(BaseLeagueMember<?, ?, ?, ?,?> member, AdInfo adInfo) {
        LogHelper.d("联盟=" + member.getName(), "Splash广告onDownloadTipsDialogCancel", "appId=" + adInfo.getMapAppid(), "pid=" + adInfo.getMapPid());
        onDownloadTipsDialogCancel();
    }

    @Override
    public void setOnADExposeListener(OnADExposeListener onADExposeListener) {
        this.onADExposeListener = onADExposeListener;
    }

    @Override
    public void setOnShowErrorListener(OnShowErrorListener listener) {
        mOnShowErrorListener = listener;
    }

    @Override
    public void setOnPreloadErrorListener(OnPreloadErrorListener onPreloadErrorListener) {
        this.mOnPreloadErrorListener = onPreloadErrorListener;
    }

    public abstract void onADClicked();

    public abstract void onADDismissed();

    public abstract void onADExposure();

    public abstract void onADLoaded(long l);

    public abstract void onADPresent();

    public abstract void onADTick(long l);

    public abstract void onNoAD(ZxError error);

    public abstract void onPreLoadNoAD(ZxError error);

    public abstract void onDownloadTipsDialogShow();

    public abstract void onDownloadTipsDialogDismiss();

    public abstract void onDownloadTipsDialogCancel();
}
